/**
 ****************************************************************************************
 *
 * @file user.h
 *
 * @brief Header file - Letstrong Rope Profile Sensor.
 *
 * Copyright (C) Letstrong 2021-2022
 *
 *
 ****************************************************************************************
 */

#ifndef _USER_H_
#define _USER_H_

/*
 * INCLUDE FILES
 ****************************************************************************************
 */
#include "user_config.h"

#if (BLE_USER_SENSOR)

#include "prf_types.h"
#include "prf.h"
#include "user_task.h"
#include "attm.h"

/*
 * DEFINES
 ****************************************************************************************
 */
///Maximum number of USER task instances
#define USER_SENSOR_IDX_MAX     0x01

///USER Configuration Flag Masks
#define USER_MANDATORY_MASK              (0xFFFF)


#define USER_PRIMARY_SVC_UUID             0xFFD0
#define USER_SVC_WRITE_CHAR_UUID          0xFFD1
#define USER_SVC_INDICATE_CHAR_UUID       0xFFD2


/*
 * MACROS
 ****************************************************************************************
 */

#define USER_IS_SUPPORTED(mask) \
    (((user_env->prfl_cfg & mask) == mask))

/// Possible states of the BLPS task
enum
{
    /// Idle state
    USER_IDLE,
    /// Busy state
    USER_BUSY,

    /// Number of defined states.
    USER_STATE_MAX
};


///Attributes State Machine
enum
{
	USER_IDX_SVC = 0,

	USER_IDX_WRITE_CHAR,
	USER_IDX_WRITE_VAL,

	USER_IDX_IND_CHAR,
	USER_IDX_IND_VAL,
	USER_IDX_IND_CFG,

    USER_IDX_NB,
};

/*
 * TYPE DEFINITIONS
 ****************************************************************************************
 */

/// User Profile Sensor environment variable
struct user_env_tag
{
    /// profile environment
    prf_env_t prf_env;
    /// User Service Start Handle
    uint16_t start_hdl;
    /// Feature Configuration Flags
    uint16_t features;
    /// Profile configuration flags
    uint8_t prfl_cfg;
    /// Event (notification/indication) config
    uint8_t evt_cfg;
    /// Environment variable pointer for each connections
    uint8_t ind_cfg[BLE_CONNECTION_MAX];
    /// State of different task instances
    ke_state_t state[USER_SENSOR_IDX_MAX];
};


/*
 * GLOBAL VARIABLE DECLARATIONS
 ****************************************************************************************
 */

/*
 * FUNCTION DECLARATIONS
 ****************************************************************************************
 */

const struct prf_task_cbs* user_prf_itf_get(void);
extern bool user_indicate_data(struct user_ind_upd_req const *param);

/*
 * TASK DESCRIPTOR DECLARATIONS
 ****************************************************************************************
 */
extern const struct ke_state_handler user_default_handler;

#endif /* #if (BLE_USER_SENSOR) */

/// @} USER

#endif /* _USER_H_ */
